<?php
class CourseDao {
	public $table='course';
	public function getByname($id){
		return ClassManager::getSql()->onedata($this->table,'*',"where id =".intval($id));
	}
	
	public function getDataPairList($strs_list){
		$strs = implode(',', $strs_list);
		return ClassManager::getSql()->dataPairList($this->table,'id,theme,serial_number'," where id in (".$strs.")");
	}
	
	public function add($data){
		ClassManager::getSql()->insert($this->table, $data);
	}
	public function update($data,$id){
		ClassManager::getSql()->updates($this->table, $data,"where id=".intval($id));
	}
	
	public function searchList($where=array(),$order='',$limit=0){
		$where = $this->searchWhere($where);
		return ClassManager::getSql()->dataList1($this->table,'*',$where,$order,$limit);
	}

	
	public function searchPairList($where=array(),$order='',$limit=0){
		$where = $this->searchWhere($where);
		return ClassManager::getSql()->dataList1($this->table,'id,theme,type,serial_number',$where,$order,$limit);
	}
	
	public function searchNumber($where){
		$where = $this->searchWhere($where);
		$tmp = ClassManager::getSql()->onedata1($this->table,"count(*)  ",$where);
		return $tmp[0];
	}
	public function getListByType($type){
		return ClassManager::getSql()->datalist($this->table,' * ',"where type='".$type."'");
	}
	public function searchWhere($where){
		$likeWhere = array('serial_number','theme','for_purpose_study','for_purpose_people');
		if (!empty($where['start_level'])){
			$where['level'][] = array($where['start_level'],'>=');
		}
		if (!empty($where['end_level'])){
			$where['level'][] = array($where['end_level'],'<=');
		}
		
		$where1 = array();
		foreach ($where as  $k=>$v){
			if (!empty($v)){
				if (in_array($k,$likeWhere) and !is_array($v)){
					$where1[$k] = array('%'.$v.'%' , 'like');
				}else{
					$where1[$k] = $v;
				}
			}
		}
		return $where1;
	}
	public function deleteBatchByid($id){
		ClassManager::getSql()->delete($this->table,"where id in(".$id.")");
	}
	public function getSerialNumber($serialNumber){
		return ClassManager::getSql()->oneDataCache($this->table,'serial_number',$serialNumber);
	}
	public function get($id){
		return ClassManager::getSql()->oneDataCache($this->table, 'id', intval($id));
	}
}

?>